<?php
class v1_binding{
    function index(){
    	$data['basic']=$this->yum->config['Manage']['domain'].'?c=binding&a=index';
		$params=array();$params['where']['B.locked !=']=10;$params['where']['A.account !=']='';
		if($this->yum->get('search',true)){
			$data['search']=urldecode($this->yum->get('search',true));$data['tab']=$this->yum->get('tab',true);
			if($data['search']!=''){
				if($data['tab']=='mail'){
					$params['where']['B.mail LIKE']='%'.$data['search'].'%';
				}else if($data['tab']=='account'){
					$params['where']['A.name LIKE']='%'.$data['search'].'%';
				}
				$data['basic'].='&tab='.$data['tab'];
				$data['basic'].='&search='.urlencode($data['search']);
			}
		}
		$mation=$this->yum->model('information');
		$data['total']=$mation->GMationFull(array('select'=>'COUNT(*) AS count','where'=>$params['where']));
		$data['total']=empty($data['total'])?0:$data['total'][0]['count'];
		$params['limit']=array(intval($this->yum->get('start')),15);
		$data['mation']=$mation->GMationFull($params);
		$pagination=$this->yum->library('pagination',array('query_string'=>'start','base_url'=>$data['basic'].'&order='.$data['order'].'&rule='.$data['rule'],'total_rows'=>$data['total'],'per_page'=>15,'first_link'=>'首页','last_link'=>'末页','cur_tag_open'=>'<a href="#" class="active">','cur_tag_close'=>'</a>'));
		$data['pagination']=$pagination->create_links();
		$this->yum->set($data);
		$this->yum->view('index.php');
    }
    function edit(){
		$mation=$this->yum->model('information');
		if($this->yum->post('save')){
			$output=array('result'=>0,'msg'=>'');
			$member=intval($this->yum->post('member',true));$account=$this->yum->post('account',true);
			$affected=$mation->UMation(array('where'=>array('member='=>$member),'set'=>array('account='=>$account)));
			if($affected==1){
				$output['result']=2;
				$output['msg']='修改成功.';
			}else{
				$output['msg']='请误提交相同或未经修改的数据.';
			}
			header('Content-type:application/json');
			echo json_encode($output);
		}else{
			$data['bind']=$mation->GMation(array('where'=>array('member ='=>intval($this->yum->get('member')))));
			$data['bind']=reset($data['bind']);
			$this->yum->set($data);
			$this->yum->view('edit.php');
		}
    }
}
?>